﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;
using System.IO;


public partial class QuarterPlan_NoVerifyQuarterPlan : System.Web.UI.Page
{
    Authentication dllAuthentication = new Authentication();
    QuarterPlanofManager dllQuarterPlan = new QuarterPlanofManager();
    QuarterDateManager dllQuarterDateManager = new QuarterDateManager();
    IBussinessLogic dllUserInfo = new UserInfoManager();
    IBussinessLogic dllQuarterPlanDetail = new QuarterPlanDetailManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    DataTable _powerTable = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        _powerTable = dllAuthentication.getPower(objUserInfo.UserName, "待处理年计划");
        for (int i = 0; i < _powerTable.Rows.Count; i++)
        {
            if (_powerTable.Rows[i]["PowerName"].ToString() == "新建")
            {
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "删除")
            {
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "查看")
            {
                this.btnVerifyCircuit.Visible = true;
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "修改")
            {
                this.btnOk.Visible = true;
            }
        }
        if (!IsPostBack)
        {
            #region 弹出提醒
            PopupManager dllPopupManager = new PopupManager();
            string _info = dllPopupManager.getPopupInfo();
            if (_info.Length > 0)
            {
                ShowMessage(_info);
            }
            #endregion
            bindDropDownList(this.drpYear);
            bindDropDownList(this.drpQuarterDate);
             
            if (Request.Params["type"] != null && Request.Params["type"].ToString().Length != 0)
            {
                this.drpType.SelectedIndex = this.drpType.Items.IndexOf(this.drpType.Items.FindByValue(Request.Params["type"].ToString()));
            }

            if (this.drpType.SelectedItem.Value == "0")
            {
                //绑定待评估
                bindGridViewCheckNote();
                this.gdvQuarterPlan.Visible = false;
                this.btnOk.Visible = false;
                this.btnVerifyCircuit.Visible = true;
                this.btnReturn.Visible = false;
            }
            else
            {
                //绑定是否达成共识
                bindGridView();
                this.gdvEvaluateCheckNote.Visible = false;
                this.btnOk.Visible = true;
                this.btnVerifyCircuit.Visible = true;
                this.btnReturn.Visible = true;
            }



        }
    }

    /// <summary>
    /// 弹出小窗体事件
    /// </summary>
    /// <param name="msg"></param>
    public void ShowMessage(string msg)
    {
        EeekSoft.Web.PopupWin pop = new EeekSoft.Web.PopupWin();
        this.Controls.Add(pop);
        pop.Text = msg;
        pop.Message = msg;
        pop.Title = System.Configuration.ConfigurationManager.AppSettings["CompanyName"].ToString();
        pop.WindowScroll = true;
        pop.HideAfter = 99999999;
        pop.DockMode = EeekSoft.Web.PopupDocking.BottomLeft;
        pop.OffsetX = int.Parse(Session["_width"].ToString()) - 338;
        pop.ActionType = EeekSoft.Web.PopupAction.MessageWindow;
        pop.OffsetY = 1;
        pop.Width = 220;
        pop.Height = 170;
    }

    /// <summary>
    /// 绑定DropDownList
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-16</date>
    void bindDropDownList(DropDownList _drp)
    {
        if (_drp.Equals(this.drpYear))
        {
            for (int i = 2009; i < 2100; i++)
            {
                ListItem li = new ListItem(i.ToString(), i.ToString());
                _drp.Items.Add(li);
            }
            //根据系统日期自动绑定到当前年份
            //string _year = DateTime.Now.Year.ToString();
            //this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year));
            //根据系统当前日期查找到对应的年周期
            DataTable _year = dllQuarterDateManager.getQuarterDate();
            this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year.Rows[0][2].ToString()));

        }
        if (_drp.Equals(this.drpQuarterDate))
        {
            object[] _value = new object[1];
            _value[0] = this.drpYear.SelectedValue;
            DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.QuarterYear.ToString(), _value);
            if (_quarter.Rows.Count != 0)
            {
                this.drpQuarterDate.DataSource = _quarter;
                this.drpQuarterDate.DataTextField = "QuarterName";
                this.drpQuarterDate.DataValueField = "Quarter_Id";
                this.drpQuarterDate.DataBind();
                #region dropdownlist显示系统所对应的当前年周期
                //根据系统当前日期查找到对应的年周期
                DataTable _quartertime = dllQuarterDateManager.getQuarterDate();
                //如果查到结果（结果只有一条）

                if (_quartertime.Rows.Count == 1)
                {
                    this.drpQuarterDate.SelectedIndex = this.drpQuarterDate.Items.IndexOf(this.drpQuarterDate.Items.FindByText(_quartertime.Rows[0][1].ToString()));
                    this.drpQuarterDate.DataSource = _quartertime;
                    this.drpQuarterDate.DataTextField = "QuarterName";
                    this.drpQuarterDate.DataValueField = "Quarter_Id";
                }
                if (Request.QueryString["Id"] != null)
                {
                    this.drpQuarterDate.SelectedValue = Utility.HttpHelp.getParamsInt("Id").ToString();
                }
                #endregion
                ListItem _li = this.drpType.SelectedItem;
                if (_li != null && _li.Value != "无年周期")
                {
                    if (_li.Text == "待审核")
                    {
                        bindGridView();
                    }
                    else
                    {
                        bindGridViewCheckNote();
                    }
                }

            }
            else
            {
                ListItem li = new ListItem("无年周期");
                this.drpQuarterDate.Items.Clear();
                this.drpQuarterDate.Items.Add(li);
                this.gdvQuarterPlan.DataSource = new DataTable();
                this.gdvQuarterPlan.DataBind();
            }

        }



        #region 下载文件
        for (int i = 0; i < this.gdvQuarterPlan.Rows.Count; i++)
        {

            if (this.gdvQuarterPlan.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
            {
                Button _btn = (Button)this.gdvQuarterPlan.Rows[i].Cells[12].FindControl("btnDownLoad");
                _btn.Visible = false;
                Label _lbl = (Label)this.gdvQuarterPlan.Rows[i].Cells[12].FindControl("lblAlert");
                _lbl.Visible = true;
                _lbl.Text = "无附件";
            }

        }
        #endregion

    }


    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    void wrapByComma(GridView _gridView, int _rowIndex, int _cells)
    {
        string _content = _gridView.Rows[_rowIndex].Cells[_cells].Text;
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _gridView.Rows[_rowIndex].Cells[_cells].Text.Replace(",", "<br>");


    }

    /// <summary>
    /// 绑定待审核GridView（处理待评估、待审核计划）
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-25</date>
    void bindGridView()
    {
        //根据评估人查询当前用户的待审待评估计划
        Model.UserInfo objUserInfo = new Model.UserInfo();
        object[] _value = new object[2];
        _value[0] = objUserInfo.UserName;
        ListItem _li = this.drpQuarterDate.SelectedItem;
        if (_li != null && _li.Value != "无年周期")
        {
            _value[1] = Convert.ToInt32(_li.Value);
            DataView dv = new DataView(dllQuarterPlan.getQuarterPlanNoEvaluateAndNoVerify(_value));
            dv.Sort = "QuarterPlanSortId";
            this.gdvQuarterPlan.DataSource = dv;
            this.gdvQuarterPlan.DataBind();
            #region 截取字符串
            for (int i = 0; i < this.gdvQuarterPlan.Rows.Count; i++)
            {
                LinkButton lbtn = (LinkButton)gdvQuarterPlan.Rows[i].Cells[4].FindControl("lbtnSourceShenhe");
                lbtn.Text = gdvQuarterPlan.DataKeys[i]["Source"].ToString();
                TextBox tb = (TextBox)this.gdvQuarterPlan.Rows[i].Cells[13].FindControl("txtVerifyPeopleOpinion");
                tb.Text = gdvQuarterPlan.DataKeys[i]["VerifyPeopleOpinion"].ToString();
                if (tb.Text.Length > 0)
                {
                    tb.Enabled = false;
                }
                else
                {
                    tb.Enabled = true;
                }
                object[] _valueQuarterPlanResolve = new object[1];
                _valueQuarterPlanResolve[0] = this.gdvQuarterPlan.DataKeys[i]["QuarterPlanId"].ToString();
                DataTable _quarterResolve = dllQuarterPlanDetail.get(QuarterPlanDetailManager.field.QuarterPlanId.ToString(), _valueQuarterPlanResolve);
                if (_quarterResolve.Rows.Count > 0)
                {
                    Button btn = (Button)this.gdvQuarterPlan.Rows[i].Cells[10].FindControl("btnSelectResolvQuarterPlan");
                    Label lbl = (Label)this.gdvQuarterPlan.Rows[i].Cells[10].FindControl("lblTopic");
                    btn.Visible = true;
                    lbl.Visible = false;
                }
                else
                {
                    Button btn = (Button)this.gdvQuarterPlan.Rows[i].Cells[10].FindControl("btnSelectResolvQuarterPlan");
                    Label lbl = (Label)this.gdvQuarterPlan.Rows[i].Cells[10].FindControl("lblTopic");
                    btn.Visible = false;
                    lbl.Visible = true;
                }
                wrapByComma(this.gdvQuarterPlan, i, 7);
                wrapByComma(this.gdvQuarterPlan, i, 8);
                if (this.gdvQuarterPlan.Rows[i].Cells[11].Text == "&nbsp;" || this.gdvQuarterPlan.Rows[i].Cells[11].Text == "&amp;nbsp;")
                {
                    this.gdvQuarterPlan.Rows[i].Cells[11].Text = "";
                }
            }
            #endregion
        }

        #region 下载文件
        for (int i = 0; i < this.gdvQuarterPlan.Rows.Count; i++)
        {

            if (this.gdvQuarterPlan.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
            {
                Button _btn = (Button)this.gdvQuarterPlan.Rows[i].Cells[12].FindControl("btnDownLoad");
                _btn.Visible = false;
                Label _lbl = (Label)this.gdvQuarterPlan.Rows[i].Cells[12].FindControl("lblAlert");
                _lbl.Visible = true;
                _lbl.Text = "无附件";
            }

        }
        #endregion
    }

    /// <summary>
    /// 自动分页事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-25</date>
    protected void gdvQuarterPlan_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.gdvQuarterPlan.PageIndex = e.NewPageIndex;
        bindGridView();
    }



    /// <summary>
    /// 查看年分解计划事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-25</date>
    protected void btnSelectResolvQuarterPlan_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button bt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        int _quarterPlanId = Convert.ToInt32(this.gdvQuarterPlan.DataKeys[i]["QuarterPlanId"].ToString());
        string _url = "QuarterPlanResolveDetail.aspx?_quarterPlanId=" + _quarterPlanId;
        Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=350,width=900,top=200,left=80,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");


    }

    /// <summary>
    /// 查看年分解计划事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-25</date>
    protected void btnSelectResolvQuarterPlanEvaluate_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button bt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        int _quarterPlanId = Convert.ToInt32(this.gdvEvaluateCheckNote.DataKeys[i]["QuarterPlanId"].ToString());
        string _url = "QuarterPlanResolveDetail.aspx?_quarterPlanId=" + _quarterPlanId;
        Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=350,width=900,top=200,left=80,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");


    }




    /// <summary>
    /// 全选事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-25</date>    
    protected void ckbAllSelect_CheckedChanged(object sender, EventArgs e)
    {
        if (ckbAllSelect.Checked == true)
        {
            for (int i = 0; i < this.gdvQuarterPlan.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvQuarterPlan.Rows[i].Cells[0].FindControl("ckbSelect");
                ckb.Checked = true;
            }
        }
        else
        {
            for (int i = 0; i < this.gdvQuarterPlan.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvQuarterPlan.Rows[i].Cells[0].FindControl("ckbSelect");
                ckb.Checked = false;
            }
        }
    }


    /// <summary>
    /// 评估通过事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-25</date>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        //根据评估人查询当前用户的待审计划
        Model.UserInfo objUserInfo = new Model.UserInfo();
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvQuarterPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvQuarterPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                object[] _value = new object[3];
                _value[0] = Convert.ToInt32(this.gdvQuarterPlan.DataKeys[i]["QuarterPlanId"].ToString());
                _value[1] = objUserInfo.UserName;
                TextBox tb = (TextBox)this.gdvQuarterPlan.Rows[i].Cells[13].FindControl("txtVerifyPeopleOpinion");
                //if (tb.Text.Length < 18)
                //{
                //    Utility.HttpHelp.alert("审核意见不得少于32个字符", Page);
                //    return;
                //}
                _value[2] = tb.Text;
                _valueList.Add(_value);
                _count++;
            }
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请至少选择一个年计划", Page);
            return;
        }
        if (this.drpType.SelectedItem != null && this.drpType.SelectedItem.Value == "1")
        { //修改发送状态为2，进入审核流程

            int result = dllQuarterPlan.editWithTransaction(QuarterPlanofManager.field.EvaluatePeople.ToString(), _valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("提交年计划评估未成功，请重试！");
            }
            else
            {
                Response.Redirect("NoEvaluateQuarterPlan.aspx");
            }
        }
        else
        {

            int result = dllQuarterPlan.editWithTransaction1(QuarterPlanofManager.field.EvaluatePeople.ToString(), _valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("提交年计划评估意见未成功，请重试！");
            }
            else
            {
                Response.Redirect("NoEvaluateQuarterPlan.aspx");
            }
        }
    }



    /// <summary>
    /// 退回事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-25</date>
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        //int i = 0;
        //Button bt = (Button)sender;//获得当前控件
        //TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        //GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        //i = iRow.RowIndex;//得到该行的索引
        //object[] _value = new object[2];
        //_value[0] = Convert.ToInt32(this.gdvQuarterPlan.DataKeys[i]["QuarterPlanId"].ToString());
        //_value[1] = ((TextBox)this.gdvQuarterPlan.Rows[i].Cells[11].FindControl("txtCheckNote")).Text;        
        ////修改年计划发送状态为-1，填写checknote字段内容（追加）
        //int result = dllQuarterPlan.edit(QuarterPlanofManager.field.CheckNote.ToString(), _value);
        //if (result == 0)
        //{
        //    Utility.Error.RedirectErrorPage("退回年计划未成功，请重试！");
        //}
        //else
        //{
        //    bindGridView();
        //    //Response.Redirect("NoEvaluateQuarterPlan.aspx");
        //}

        //根据评估人查询当前用户的待审计划
        Model.UserInfo objUserInfo = new Model.UserInfo();
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvQuarterPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvQuarterPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                object[] _value = new object[2];
                _value[0] = Convert.ToInt32(this.gdvQuarterPlan.DataKeys[i]["QuarterPlanId"].ToString());
                TextBox tb = (TextBox)this.gdvQuarterPlan.Rows[i].Cells[13].FindControl("txtVerifyPeopleOpinion");
                _value[1] = tb.Text;
                _valueList.Add(_value);
                _count++;
            }
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请至少选择一个年计划", Page);
            return;
        }
        int result = dllQuarterPlan.editWithTransaction(QuarterPlanofManager.field.CheckNote.ToString(), _valueList);
        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("退回年计划未成功，请重试！");
        }
        else
        {
            Response.Redirect("NoEvaluateQuarterPlan.aspx");
        }

    }


    /// <summary>
    /// 评估类型改变项事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.drpType.SelectedItem.Value == "0")
        {
            //绑定待评估
            bindGridViewCheckNote();
            this.gdvEvaluateCheckNote.Visible = true;
            this.gdvQuarterPlan.Visible = false;
            this.btnOk.Visible = false;
            this.btnReturn.Visible = false;

        }
        else
        {
            //绑定是否达成共识
            bindGridView();
            this.gdvQuarterPlan.Visible = true;
            this.gdvEvaluateCheckNote.Visible = false;
            this.btnOk.Visible = true;
            this.btnReturn.Visible = true;
        }
    }
    /// <summary>
    /// 绑定待评估GridView
    /// </summary>
    void bindGridViewCheckNote()
    {
        //根据评估人查询当前用户的待最后一次评估的计划
        Model.UserInfo objUserInfo = new Model.UserInfo();
        object[] _value = new object[2];
        _value[0] = objUserInfo.UserName;
        ListItem _li = this.drpQuarterDate.SelectedItem;
        if (_li != null && _li.Value != "无年周期")
        {
            _value[1] = Convert.ToInt32(_li.Value);
            DataView dv = new DataView(dllQuarterPlan.getQuarterPlanEvaluatedAndVerified(_value));
            dv.Sort = "QuarterPlanSortId";
            this.gdvEvaluateCheckNote.DataSource = dv;
            this.gdvEvaluateCheckNote.DataBind();
            #region 截取字符串
            for (int i = 0; i < this.gdvEvaluateCheckNote.Rows.Count; i++)
            {
                LinkButton lbtn = (LinkButton)gdvEvaluateCheckNote.Rows[i].Cells[4].FindControl("lbtnSourceChuli");
                lbtn.Text = gdvEvaluateCheckNote.DataKeys[i]["Source"].ToString();
                DropDownList drp = (DropDownList)this.gdvEvaluateCheckNote.Rows[i].Cells[11].FindControl("dropZhuangTai");
                drp.SelectedValue = this.gdvEvaluateCheckNote.DataKeys[i]["PlanSendState"].ToString();
                drp.SelectedValue = "4";
                //禁止2次评估
                //if (Convert.ToInt32(this.gdvEvaluateCheckNote.DataKeys[i]["NoCompleteCount"].ToString()) > 0)
                //{
                //    Button btn = (Button)this.gdvEvaluateCheckNote.Rows[i].Cells[11].FindControl("btnTiJiao");
                //    btn.Enabled = false;
                //}
                #region 查看年计划分解
                object[] _valueQuarterPlanResolve = new object[1];
                _valueQuarterPlanResolve[0] = this.gdvEvaluateCheckNote.DataKeys[i]["QuarterPlanId"].ToString();
                DataTable _quarterResolve = dllQuarterPlanDetail.get(QuarterPlanDetailManager.field.QuarterPlanId.ToString(), _valueQuarterPlanResolve);
                if (_quarterResolve.Rows.Count > 0)
                {
                    Button btn = (Button)this.gdvEvaluateCheckNote.Rows[i].Cells[10].FindControl("btnSelectResolvQuarterPlan");
                    Label lbl = (Label)this.gdvEvaluateCheckNote.Rows[i].Cells[10].FindControl("lblTopic");
                    btn.Visible = true;
                    lbl.Visible = false;
                }
                else
                {
                    Button btn = (Button)this.gdvEvaluateCheckNote.Rows[i].Cells[10].FindControl("btnSelectResolvQuarterPlan");
                    Label lbl = (Label)this.gdvEvaluateCheckNote.Rows[i].Cells[10].FindControl("lblTopic");
                    btn.Visible = false;
                    lbl.Visible = true;
                }
                wrapByComma(this.gdvEvaluateCheckNote, i, 7);
                wrapByComma(this.gdvEvaluateCheckNote, i, 8);
                if (this.gdvEvaluateCheckNote.Rows[i].Cells[11].Text == "&nbsp;" || this.gdvEvaluateCheckNote.Rows[i].Cells[11].Text == "&amp;nbsp;")
                {
                    this.gdvEvaluateCheckNote.Rows[i].Cells[11].Text = "";
                }
                #endregion
            }
            #endregion
        }

        #region 下载文件
        for (int i = 0; i < this.gdvEvaluateCheckNote.Rows.Count; i++)
        {

            if (this.gdvEvaluateCheckNote.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
            {
                Button _btn = (Button)this.gdvEvaluateCheckNote.Rows[i].Cells[13].FindControl("btnDownLoad1");
                _btn.Visible = false;
                Label _lbl = (Label)this.gdvEvaluateCheckNote.Rows[i].Cells[13].FindControl("lblAlert1");
                _lbl.Visible = true;
                _lbl.Text = "无附件";
            }

        }
        #endregion

    }
    /// <summary>
    /// 是否达成共识提交按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnTiJiao_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button bt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        DropDownList drp = (DropDownList)this.gdvEvaluateCheckNote.Rows[i].Cells[11].FindControl("dropZhuangTai");
        ListItem _li = drp.SelectedItem;

        if (_li != null)
        {
            if (_li.Text != "请选择")
            {
                object[] _value = new object[3];
                _value[0] = Convert.ToInt32(this.gdvEvaluateCheckNote.DataKeys[i]["QuarterPlanId"].ToString());
                TextBox tb = (TextBox)this.gdvEvaluateCheckNote.Rows[i].Cells[11].FindControl("txtCheckNote");
                if (tb.Text.Length < 18)
                {
                    Utility.HttpHelp.alert("评估意见不得少于32个字符", Page);
                    return;
                }
                tb.Text = tb.Text + "\r\n";
                _value[1] = tb.Text;
                _value[2] = Convert.ToInt32(_li.Value);
                //填写checknote字段内容（追加）
                int result = dllQuarterPlan.edit(QuarterPlanofManager.field.CheckNote.ToString(), QuarterPlanofManager.field.PlanSendState.ToString(), _value);
                if (result == 0)
                {
                    Utility.Error.RedirectErrorPage("提交评估意见未成功，请重试！");
                }
                else
                {
                    bindGridViewCheckNote();
                }
            }
            else
            {
                Utility.HttpHelp.alert("请选择计划完成状态", Page);
            }
        }
    }
    /// <summary>
    ///   查看流程
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnVerifyCircuit_Click(object sender, EventArgs e)
    {
        int _count = 0;
        string _url = "";
        int _quarterPlanId = 0;
        if (this.gdvQuarterPlan.Visible)
        {
            for (int i = 0; i < this.gdvQuarterPlan.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvQuarterPlan.Rows[i].Cells[0].FindControl("ckbSelect");
                if (ckb.Checked == true)
                {
                    _count++;
                    _quarterPlanId = Convert.ToInt32(this.gdvQuarterPlan.DataKeys[i]["QuarterPlanId"].ToString());
                }
            }
        }
        else
        {
            for (int i = 0; i < this.gdvEvaluateCheckNote.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvEvaluateCheckNote.Rows[i].Cells[0].FindControl("ckbSelect");
                if (ckb.Checked == true)
                {
                    _count++;
                    _quarterPlanId = Convert.ToInt32(this.gdvEvaluateCheckNote.DataKeys[i]["QuarterPlanId"].ToString());
                }
            }
        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能选择一个计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
            return;
        }
        _url = "../WebCommon/VerifyCircruitDisplay.aspx?PlanId=" + _quarterPlanId + "&PlanType=1";
        Page.RegisterStartupScript("windowOpen",
           "<script language=javascript>window.open('" + _url + "','newwindow','height=150,width=550,top=250,left=300,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");

    }


    /// <summary>
    /// 年周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpQuarterDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListItem _li = this.drpType.SelectedItem;
        if (_li != null)
        {
            if (_li.Text == "待审核")
            {
                bindGridView();
            }
            else
            {
                bindGridViewCheckNote();
            }
        }
    }

    /// <summary>
    /// 年份改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpQuarterDate);
    }

    /// <summary>
    /// 下载附件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDownLoad_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列

        string path = this.gdvQuarterPlan.DataKeys[i]["AttachmentPath"].ToString();
        // Response.Redirect("~/upload/"+path);
        FileDownload(path);
        // Utility.HttpHelp.DownloadFile(path);
    }

    ///   <summary>   
    ///   文件下载   
    ///   </summary>   
    ///   <param   name="FullFileName"></param>   
    private void FileDownload(string strFileName)
    {

        FileInfo DownloadFile = new FileInfo(strFileName);
        if (!DownloadFile.Exists)
        {
            Utility.HttpHelp.alert("无附件,请与管理员联系", Page);
            return;
        }
        Response.Clear();
        Response.ClearHeaders();
        Response.Buffer = false;
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName.Substring(strFileName.LastIndexOf('\\') + 1), System.Text.Encoding.UTF8));
        // Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());

        Response.WriteFile(DownloadFile.FullName);
        Response.Flush();
        Response.End();

    }

    /// <summary>
    /// 评估表中的下载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDownLoad1_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列

        string path = this.gdvEvaluateCheckNote.DataKeys[i]["AttachmentPath"].ToString();
        // Response.Redirect("~/upload/"+path);
        FileDownload(path);
    }


    /// <summary>
    /// 未审核来源事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSourceShenhe_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        Control c = (Control)iRow.Parent;
        GridView _gdv = (GridView)c.Parent;

        int TotalPlanId = Convert.ToInt32(_gdv.DataKeys[i]["TotalPlanId"].ToString());
        if (TotalPlanId == 0)
        {
            //新增的月计划，不需要跳转到指定页面
        }
        else
        {
            string _url = "TotalPlanDetail.aspx?TotalPlanId=" + TotalPlanId;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height=200,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
    }


    /// <summary>
    /// 待处理来源事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSourceChuli_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        Control c = (Control)iRow.Parent;
        GridView _gdv = (GridView)c.Parent;

        int TotalPlanId = Convert.ToInt32(_gdv.DataKeys[i]["TotalPlanId"].ToString());
        if (TotalPlanId == 0)
        {
            //新增的月计划，不需要跳转到指定页面
        }
        else
        {
            string _url = "TotalPlanDetail.aspx?TotalPlanId=" + TotalPlanId;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height=200,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
    }



    /// <summary>
    /// 修改按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModify_Click(object sender, EventArgs e)
    {
        int _count = 0;
        int _quarterPlanId = 0;
        //循环上部gridview判断是否有修改的Id
        for (int i = 0; i < this.gdvQuarterPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvQuarterPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _count++;
                _quarterPlanId = Convert.ToInt32(this.gdvQuarterPlan.DataKeys[i]["QuarterPlanId"].ToString());
            }
        }
        //判断上部GridView是否有选中的记录没有则遍历下部的GridView
        if (_count == 1)
        {
            BLL.QuarterPlanofManager dllQuarterPlanofManager = new QuarterPlanofManager();
            //判断计划状态，如果以二次评估完成，则不允许修改
            object[] _value = new object[1];
            _value[0] = _quarterPlanId;
            DataTable quarterplan = dllQuarterPlanofManager.get(QuarterPlanofManager.field.QuarterPlanId.ToString(), _value);
            if (quarterplan.Rows.Count > 0)
            {
                if (Convert.ToInt32(quarterplan.Rows[0]["PlanSendState"]) >= 4)
                {
                    Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                    return;
                }
            }


            //判断是否评估人，是则允许修改
            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            if (_userTable.Rows.Count > 0)
            {
                object[] _username = new object[2];
                _username[0] = _userTable.Rows[0]["RealName"].ToString();
                _username[1] = _quarterPlanId;
                DataTable _iSEvaluatePeople = dllQuarterPlanofManager.get(QuarterPlanofManager.field.EvaluatePeople.ToString(), QuarterPlanofManager.field.QuarterPlanId.ToString(), _username);
                if (_iSEvaluatePeople.Rows.Count == 0)
                {
                    Utility.HttpHelp.alert("非评估人不能修改计划!", Page);
                }
                else
                {
                    ListItem _li = this.drpQuarterDate.SelectedItem;
                    if (_li != null)
                    {
                        string _url = "ModifyQuarterPlanDraft.aspx?_quarterPlanId=" + _quarterPlanId + "&_quarterDate=" + _li.Value + "&url=NoEvaluateQuarterPlan.aspx";
                        Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=900,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                        return;
                    }
                }
            }
        }
        else
        {

            //循环下部gridview判断是否有修改的Id
            for (int i = 0; i < this.gdvEvaluateCheckNote.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvEvaluateCheckNote.Rows[i].Cells[0].FindControl("ckbSelect");
                if (ckb.Checked == true)
                {
                    _count++;
                    _quarterPlanId = Convert.ToInt32(this.gdvEvaluateCheckNote.DataKeys[i]["QuarterPlanId"].ToString());
                }
            }
            //判断下部GridView是否又被选中的
            if (_count == 1)
            {
                BLL.QuarterPlanofManager dllQuarterPlanofManager = new QuarterPlanofManager();
                //判断计划状态，如果以二次评估完成，则不允许修改
                object[] _value = new object[1];
                _value[0] = _quarterPlanId;
                DataTable quarterplan = dllQuarterPlanofManager.get(QuarterPlanofManager.field.QuarterPlanId.ToString(), _value);
                if (quarterplan.Rows.Count > 0)
                {
                    if (Convert.ToInt32(quarterplan.Rows[0]["PlanSendState"]) >= 4)
                    {
                        Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                        return;
                    }
                }


                //判断是否评估人，是则允许修改
                Model.UserInfo objUser = new Model.UserInfo();
                object[] _user = new object[1];
                _user[0] = objUser.UserName;
                DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
                if (_userTable.Rows.Count > 0)
                {
                    object[] _username = new object[2];
                    _username[0] = _userTable.Rows[0]["RealName"].ToString();
                    _username[1] = _quarterPlanId;
                    DataTable _iSEvaluatePeople = dllQuarterPlanofManager.get(QuarterPlanofManager.field.EvaluatePeople.ToString(), QuarterPlanofManager.field.QuarterPlanId.ToString(), _username);
                    if (_iSEvaluatePeople.Rows.Count == 0)
                    {
                        Utility.HttpHelp.alert("非评估人不能修改计划!", Page);
                    }
                    else
                    {
                        ListItem _li = this.drpQuarterDate.SelectedItem;
                        if (_li != null)
                        {
                            string _url = "ModifyQuarterPlanDraft.aspx?_quarterPlanId=" + _quarterPlanId + "&_quarterDate=" + _li.Value + "&url=NoEvaluateQuarterPlan.aspx";
                            Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=900,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                            return;
                        }
                    }
                }
            }
            if (_count > 1)
            {
                Utility.HttpHelp.alert("只能修改一个计划", Page);
                return;
            }
            if (_count == 0)
            {
                Utility.HttpHelp.alert("请选择一个计划", Page);
                return;
            }
        }
    }
}
